package bishi.tengxun;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/08/22 20:02
 */
public class one {
    static class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }

    public static void main(String[] args) {
        ListNode a = new ListNode(7);
        a.next = new ListNode(8);
        a.next.next = new ListNode(13);
        a.next.next.next = new ListNode(11);
        a.next.next.next.next = new ListNode(15);
        a.next.next.next.next.next = new ListNode(0);
        a.next.next.next.next.next.next = new ListNode(10);
        a.next.next.next.next.next.next.next = new ListNode(15);
        a.next.next.next.next.next.next.next.next = new ListNode(9);
        a.next.next.next.next.next.next.next.next.next = new ListNode(9);
        solve(9, a);
    }

    public static ListNode[] solve(int m, ListNode a) {
        ListNode[] res = new ListNode[m];
        ListNode[] wei = new ListNode[m];//记录尾节点
        while (a != null) {
            int index = a.val % m;
            ListNode temp = a;
            if (res[index] == null) {
                res[index] = temp;
                wei[index] = temp;
            } else {
                wei[index].next = temp;
                wei[index] = temp;
            }
            a = a.next;
        }
        return res;
    }
}
